package com.fr.report.js;

import com.fr.base.CodeUtils;
import com.fr.base.FRContext;
import com.fr.base.StringUtils;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.report.parameter.Parameter;
import com.fr.web.Repository;
import java.util.logging.Level;
import java.util.logging.Logger;

public class WebHyperlink extends AbstractHyperlink
{
  private String url;
  private boolean useCJK;

  public WebHyperlink()
  {
    this.url = "";
    this.useCJK = true;
  }

  public WebHyperlink(String paramString)
  {
    this(paramString, "");
  }

  public WebHyperlink(String paramString1, String paramString2)
  {
    this.url = "";
    this.useCJK = true;
    setURL(paramString1);
    setTargetFrame(paramString2);
  }

  public String getURL()
  {
    return this.url;
  }

  public void setURL(String paramString)
  {
    this.url = paramString;
  }

  public boolean isUseCJK()
  {
    return this.useCJK;
  }

  public void setUseCJK(boolean paramBoolean)
  {
    this.useCJK = paramBoolean;
  }

  public String createURL(Repository paramRepository)
  {
    try
    {
      return createWebPath(paramRepository);
    }
    catch (Exception localException)
    {
      FRContext.getLogger().log(Level.WARNING, localException.getMessage(), localException);
    }
    return null;
  }

  private String createWebPath(Repository paramRepository)
    throws Exception
  {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append("FR.doHyperlinkByGet");
    localStringBuffer.append("(\"");
    localStringBuffer.append(CodeUtils.encodeURIComponent(CodeUtils.cjkEncode(getURL())));
    localStringBuffer.append("\", ");
    localStringBuffer.append(createParaPath(paramRepository));
    localStringBuffer.append(", \"");
    localStringBuffer.append(getTargetFrame());
    localStringBuffer.append("\", \"");
    localStringBuffer.append(features4NewWindow());
    localStringBuffer.append("\")");
    return localStringBuffer.toString();
  }

  private JSONObject createParaPath(Repository paramRepository)
    throws Exception
  {
    JSONObject localJSONObject = new JSONObject();
    for (int i = 0; i < this.parameters.length; ++i)
    {
      Parameter localParameter = this.parameters[i];
      Object localObject = localParameter.getValue();
      if (localObject == null)
        break label93:
      localJSONObject.put((this.useCJK) ? CodeUtils.cjkEncode(localParameter.getName()) : localParameter.getName(), (this.useCJK) ? CodeUtils.cjkEncode(localParameter.valueToString()) : localParameter.valueToString());
    }
    label93: return localJSONObject;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str2;
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("URL"))
      {
        str2 = null;
        if (StringUtils.isNotBlank(str2 = paramXMLableReader.getElementValue()))
          setURL(str2);
      }
      else if (str1.equals("CJK"))
      {
        str2 = null;
        if (StringUtils.isNotBlank(str2 = paramXMLableReader.getElementValue()))
          setUseCJK(Boolean.valueOf(str2).booleanValue());
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("JavaScript").attr("class", getClass().getName());
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("URL").textNode(getURL()).end();
    if (!(isUseCJK()))
      paramXMLPrintWriter.startTAG("CJK").textNode(String.valueOf(isUseCJK())).end();
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (paramObject == this)
      return true;
    if (!(paramObject instanceof WebHyperlink))
      return false;
    return ((super.equals(paramObject)) && (this.useCJK == ((WebHyperlink)paramObject).useCJK) && (ComparatorUtils.equals(this.url, ((WebHyperlink)paramObject).url)));
  }
}